import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path, { resolve } from 'path'
import { fileURLToPath } from 'url'

//import eslint from 'vite-plugin-eslint'

import { viteMockServe } from 'vite-plugin-mock'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
// https://vite.dev/config/
export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      viteMockServe({
        mockPath: 'mock',
        enable: command === 'serve', //保证开发阶段能使用mock
      }),
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]',
        // 自定义插入位置
        inject: 'body-last',
        // 是否启用预加载
        customDomId: '__svg__icons__dom__',
      }),
      // eslint({
      //   // 简化配置，让 ESLint 自动查找配置文件
      //   cache: false,
      //   include: ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx'],
      // }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          // 全局注入 SCSS 变量和混合宏
          additionalData: `
      @use "@/styles/variable.scss" as *;
          @use "@/styles/reset.scss" as *;
        `,
        },
      },
    },

    resolve: {
      alias: {
        '@': path.resolve('./src'), // 相对路径别名配置，使用 @ 代替 src
        // '@components': resolve(__dirname, 'src/components'), // Add this line
        //'@views': resolve(__dirname, 'src/views'), // Add this line
      },
    },
  }
})
